package q1.project.modules.system.dept.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import q1.project.core.entity.BaseEntity;
import q1.project.core.jpa.annotation.Comment;

/**
 * 部门实体
 *
 * @author Q1 Team
 * @version 1.0
 */
@Getter
@Setter
@Entity
@Table(
    name = "q1_dept",
    indexes = {
      @Index(name = "idx_dept_code", columnList = "dept_code"),
      @Index(name = "idx_parent_id", columnList = "parent_id"),
      @Index(name = "idx_status", columnList = "status")
    })
public class DeptEntity extends BaseEntity {

  /** 部门编码 */
  @Comment("部门编码")
  @Column(name = "dept_code", unique = true, nullable = false, length = 50)
  private String deptCode;

  /** 部门名称 */
  @Comment("部门名称")
  @Column(name = "dept_name", nullable = false, length = 100)
  private String deptName;

  /** 父部门ID */
  @Comment("父部门ID")
  @Column(name = "parent_id", length = 32)
  private String parentId;

  /** 父部门名称 */
  @Comment("父部门名称")
  @Column(name = "parent_name", length = 100)
  private String parentName;

  /** ID链路（用于快速查询部门树，格式：dept_001_dept_002_dept_003） */
  @Comment("ID链路")
  @Column(name = "id_link", columnDefinition = "TEXT")
  private String idLink;

  /** 层级（从1开始） */
  @Comment("层级")
  @Column(name = "level", length = 2)
  private Integer level;

  /** 层级中文信息（如：一级部门、二级部门） */
  @Comment("层级中文信息")
  @Transient
  private String levelMsg;

  /** 部门负责人ID */
  @Comment("部门负责人ID")
  @Column(name = "leader_id", length = 32)
  private String leaderId;

  /** 部门描述 */
  @Comment("部门描述")
  @Column(columnDefinition = "TEXT")
  private String description;

  /** 排序号 */
  @Comment("排序号")
  @Column(name = "sort_order", nullable = false)
  private Integer sortOrder = 0;

  /** 状态：1-启用, 0-禁用 */
  @Comment("状态")
  @Column(nullable = false)
  private Integer status = 1;

  /** 部门电话 */
  @Comment("部门电话")
  @Column(name = "phone", length = 20)
  private String phone;

  /** 部门邮箱 */
  @Comment("部门邮箱")
  @Column(name = "email", length = 100)
  private String email;

  /** 部门地址 */
  @Comment("部门地址")
  @Column(name = "address", length = 200)
  private String address;

  public boolean isEnabled() {
    return status == 1;
  }

  public boolean isDisabled() {
    return status == 0;
  }
}
